<include file="./Application/Admin/View/default/Public/front.html"/>
<style>
    .xinzeng {
        float: left;
        margin: 0 10px;
    }

    .topic {
        width: 100%;
        height: 40px;
        line-height: 40px;
        font-size: 20px;
        font-family: Arial;
        text-align: center;
        background: #e6e6e6;
        color: #666;
    }
    .layui-body{overflow-y: scroll;}
</style>
<div class="layui-body">
    <!-- 内容主体区域 -->
    <div class="topic">课程教学任务管理</div>
    <div style="height: 10px;"></div>
    <div id="coursetasklistBody" style="padding: 10px;">
        <div><a href="http://www.sinon.com/index.php/Admin/CourseTask/add" class="layui-btn xinzeng">任务分配</a></div>
        <form class="layui-form">
            <div class="demoTable">
                快速查询：
                <div class="layui-inline">
                    <input class="layui-input" type="text" name="search" id="search" autocomplete="off"
                           placeholder="">
                </div>
                <div class="layui-btn" id="submit" lay-submit lay-filter="search">搜索</div>
            </div>
        </form>
        <table id="coursetask" lay-filter="coursetask"></table>
        <script type="text/html" id="barDemo">
            <a class="layui-btn layui-btn-xs" lay-event="edit">修改</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        </script>
    </div>
</div>

<include file="./Application/Admin/View/default/Public/behind.html"/>

<script>
    
    layui.use(['table', 'jquery'], function () {
        var table = layui.table;
        var $ = layui.jquery;
        //监听工具条
        $('#submit').on('click', function () {
            var searchValue = $('#search').val();
            table.render({
                elem: '#coursetask'
                , url: '{:U("CourseTask/index")}' //数据接口
                , method: 'post'
                , where: {search: searchValue}
                , page: true //开启分页
                , limit: 10
                , cols: [[ //表头
//                    {type: 'checkbox', fixed: 'left'},
                    {field: 'course_id', title: '课程编号', width: "10%"},
                    {field: 'course_name', title: '课程名称', width: "13%"},
                    {field: 'teacher_id', title: '教师编号', width: "10%"},
                    {field: 'teacher_name', title: '任课教师', width: "10%"},
                    {field: 'class_name', title: '班级', width: "10%"},
                    {field: 'course_workload', title: '工作量', width: "7%"},
                    {field: 'term', title: '学年度', width: "15%"},
                    {field: 'note', title: '备注', width: "10%"},
                    {field: 'right', title: '操作', align: 'center', toolbar: '#barDemo', width: "15%"}
                ]]
            });
        });


        table.on('tool(coursetask)', function (obj) {
            var data = obj.data;

            if (obj.event === 'del') {
                layer.confirm('删除此条记录？', function (index) {
                    $.ajax({
                        url: "{:U('del')}",
                        data: 'id=' + data.id,
                        method: 'post',
                        success: function (res) {
                            if (res) {
                                obj.del();
                                layer.close(index);
                                layer.msg('删除成功！！');
                            } else {
                                layer.close(index);
                                layer.msg('删除失败');
                            }
                        }
                    });
                });
            } else if (obj.event === 'edit') {
                $.ajax({
                    url: "{:U('coursetaskDetail')}",
                    data: 'id=' + data.id,
                    method: 'post',
                    success: function (res) {
//                            console.log(res);
                        $('#coursetasklistBody').html(res);
                    }
                });
            }
        });

        table.render({
            elem: '#coursetask'
            , url: '{:U("CourseTask/index")}' //数据接口
            , method: 'post'
            , page: true //开启分页
            , limit: 10
            , cols: [[ //表头
//                {type: 'checkbox', fixed: 'left'},
                {field: 'course_id', title: '课程编号', width: "10%"},
                {field: 'course_name', title: '课程名称', width: "13%"},
                {field: 'teacher_id', title: '教师编号', width: "10%"},
                {field: 'teacher_name', title: '任课教师', width: "10%"},
                {field: 'class_name', title: '班级', width: "10%"},
                {field: 'course_workload', title: '工作量', width: "7%"},
                {field: 'term', title: '学年度', width: "15%"},
                {field: 'note', title: '备注', width: "10%"},
                {field: 'right', title: '操作', align: 'center', toolbar: '#barDemo', width: "15%"}
            ]]
        });

    });

</script>


